package com.vrv.common;

import com.vrv.netmgr.R;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;

public class WaitingDialog extends Dialog {
    
    //
    private static WaitingDialog waitingDialog = null;

    //
    public WaitingDialog(Context context) {
        super(context);
    }

    //
    public WaitingDialog(Context context, int theme) {
        super(context, theme);
    }

    //
    public static WaitingDialog createDialog(Context context) {
        waitingDialog = new WaitingDialog(context, R.style.CustomProgressDialog);
        waitingDialog.setContentView(R.layout.view_waiting_dialog);
        waitingDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        return waitingDialog;
    }

    //
    public void onWindowFocusChanged(boolean hasFocus) {
        if (waitingDialog == null) {
            return;
        }
        ImageView imageView = (ImageView) waitingDialog.findViewById(R.id.loadingImageView);
        AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
        animationDrawable.start();
    }

    //
    public WaitingDialog setTitile(String strTitle) {
        return waitingDialog;
    }

    //
    public WaitingDialog setMessage(String strMessage) {
        TextView tvMsg = (TextView) waitingDialog.findViewById(R.id.tv_loadingmsg);
        if (tvMsg != null) {
            tvMsg.setText(strMessage);
        }
        return waitingDialog;
    }
}
